
{extend name='public/base' /}

{block name="content"}
<link rel="stylesheet" href="__WECHAT__/material/material.css">
{/block}

{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm LM-add" >添加素材</button>
                <button class="layui-btn layui-btn-sm layui-btn-primary LM-aysn" ><i class="fa fa-refresh"></i> 同步素材</button>
            </div>
        </div>
        <div class="layui-card-body">


            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">图片</li>
                    <li>图文</li>
                    <li>视频</li>
                    <li>音频</li>
                </ul>
                <div class="layui-tab-content" style="padding: 15px;">
                    <div class="layui-tab-item  layui-show">
                        <div class="layui-row">
                            {volist name="materialGroup['image']" id="vo"}
                            <div class="layui-col-md3">
                                <div class="media-body">
                                    <div class="media-time">
                                        发布时间：2019-08-12 : 10:38
                                    </div>
                                    <span style="display: block;">
                                  <div class="media-content">
                                        <div class="media-desc"><p class="media-desc-sp"></p></div>
                                        <img class="media-img" width="100%" height="180"
                                             src="{$vo.media_url}">
                                  </div>
                                 </span>
                                    <div>
                                        <ul>
                                        </ul>
                                    </div>
                                    <div class="media-item-type2">
                                        <div class="layui-btn-group media-btn">
                                            <button onclick="materialSend('{$vo.id}')"
                                                    class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>群发
                                            </button>
                                            <button onclick="materialPreview('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>预览
                                            </button>
                                            <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="materialDel(this,'{$vo.id}')">
                                                <i class="layui-icon layui-icon-delete"></i>删除
                                            </a>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row">
                            {volist name="materialGroup['news']" id="vo"}

                            <div class="layui-col-md3">
                                <div class="media-body">
                                    <div class="media-time">
                                        发布时间 {$vo.create_time|date="Y-m-d H:i:s"}
                                    </div>
                                    <span style="display: block;">
                                     <div class="media-content">
                                         <div class="media-desc">
                                             <p class="media-desc-sp">{if isset($vo['item_info'][0]['title'])}{$vo['item_info'][0]['title']}{/if}</p>
                                         </div>
                                            <img class="media-img"  src="{if isset($vo['item_info'][0]['cover'])}{$vo['item_info'][0]['cover']}{/if}">
                                      </div>
                                </span>
                                    <!--                                //多图文&ndash;&gt;-->
                                    {if count($vo['item_info'])>1}
                                    <div>
                                        <ul>
                                            {volist name="vo.item_info" id="v" offset='1' }
                                            <li>
                                                <div class="mdedia-lists-box">
                                                    <div class="media-title-box layui-col-md9 fl">
                                                        {$v.title}
                                                    </div>
                                                    <div class="media-img-box layui-col-md3 fr">
                                                        <img class="media-lists-img" src="{$v.cover}">
                                                    </div>
                                                </div>
                                            </li>
                                            {/volist}
                                        </ul>
                                    </div>
                                    {/if}
                                    <div class="media-item-type2">
                                        <div class="layui-btn-group media-btn">
                                            <button onclick="materialSend('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>群发
                                            </button>
                                            <button onclick="materialPreview('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>预览
                                            </button>

                                            <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="materialEdit('{$vo.id}')">
                                                <i class="layui-icon"></i>编&amp;删
                                            </a>
                                        </div>
                                    </div>
                                </div>

                            </div>

                            {/volist}
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row">
                            {volist name="materialGroup['video']" id="vo"}
                            <div class="layui-col-md3">
                                <div class="media-body">
                                    <div class="media-time">
                                        发布时间 {$vo.create_time|date="Y-m-d H:i:s"}
                                    </div>
                                    <span style="display: block;">
                                     <div class="media-content">
                                         <div class="media-desc">
                                             <p class="media-desc-sp"></p>
                                         </div>
                                         <div  style="font-size: 50px;height: 180px;line-height:180px;text-align: center">
                                             <i class="fa fa-play-circle-o"></i>
                                         </div>
                                      </div>
                                </span>

                                    <div class="media-item-type2">
                                        <div class="layui-btn-group media-btn">
                                            <button onclick="materialSend('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>群发
                                            </button>
                                            <button onclick="materialPreview('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>预览
                                            </button>

                                            <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="materialDel(this,'{$vo.id}')">
                                                <i class="layui-icon layui-icon-delete"></i>删除
                                            </a>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-row">
                            {volist name="materialGroup['voice']" id="vo"}
                            <div class="layui-col-md3">
                                <div class="media-body">
                                    <div class="media-time">
                                        发布时间 {$vo.create_time|date="Y-m-d H:i:s"}
                                    </div>
                                    <span style="display: block;">
                                     <div class="media-content">
                                         <div class="media-desc">
                                             <p class="media-desc-sp"></p>
                                         </div>
                                         <audio class="media-img"  src="{$vo.media_url}"></audio>
                                      </div>
                                </span>
                                    <!--                                //多图文&ndash;&gt;-->

                                    <div class="media-item-type2">
                                        <div class="layui-btn-group media-btn">
                                            <button onclick="materialSend('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>群发
                                            </button>
                                            <button onclick="materialPreview('{$vo.id}')" class="layui-btn layui-btn-primary layui-btn-sm">
                                                <i class="layui-icon"></i>预览
                                            </button>

                                            <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="materialDel(this,'{$vo.id}')">
                                                <i class="layui-icon layui-icon-delete"></i>删除
                                            </a>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            {/volist}
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>

{/block}


{block name="js"} <!--js处理区-->

<script>
    layui.use(['form','layer','element'], function () {
        var form = layui.form,
        layer = layui.layer;
        $ = layui.jquery;

        $('.LM-add').click(function () {
            var index = layer.open({
                title:"素材添加",
                type: 2,
                content: '{:url("materialAdd")}',
                area: ['800px', '600px'],
                anim: 2,
                maxmin: true,
            });
            layer.full(index);
        });

        $('.LM-aysn').click(function () {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("{:url('materialAysn')}",{},function(res){
                layer.close(loading);
                if(res.code==1){
                    layer.msg(res.msg,{time:1000,icon:1});
                    window.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        })

    });


    //预览
    function materialPreview(id) {
        //例子2
        layer.prompt({
            formType: 0,
            value: 'yue909',
            title: '请输入微信号',
        }, function(value, index, elem){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("{:url('materialPreview')}",{id:id,wxname:value},function(res){
                layer.close(loading);
                layer.close(index);
                if(res.code>0){
                    layer.msg(res.msg,{time:1000,icon:1});
                    obj.del();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
            layer.close(index);
        });


    }



    //群发
    function materialSend(id) {
        layer.confirm('确认群发？', function(index){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("{:url('materialSend')}",{id:id},function(res){
                layer.close(loading);
                layer.close(index);
                if(res.code>0){
                    layer.msg(res.msg,{time:1000,icon:1});
                    obj.del();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        });

    }


    //删除
    function materialDel(obj,id){
        var _that = $(obj);
        console.log(obj);
        $.post('{:url("materialDel")}',{id:id},function(res){
            if(res.code>0){
                _that.parents().parents('.layui-col-md3').remove();
                layer.msg(res.msg);
            }else {
                layer.msg(res.msg);
            }
        })
    }


    //编辑
    function materialEdit(id) {
        var index = layer.open({
            title:'编辑素材',
            type: 2,
            content: '{:url("materialEdit")}'+'?id='+id,
            area: ['80%', '80%'],
            anim: 2,
            maxmin: true,
        });
        layer.full(index);
    }

</script>

{/block}